<%@ page language="java" import="java.sql.*, java.util.Date, java.text.SimpleDateFormat;" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div class=kontakt>
<%HttpSession sesja = request.getSession(true);
if(request.getParameter("no")!=null){%>
		<div class=formularz>
		<fieldset class=obrys>	
					<%		try {
							Connection con =mb.commons.DbConnection.getConnection();
						 	Statement stmt = con.createStatement();
							String status=null,uwagi=null,oddzial=null,data_dor=null,data_nad=null;
							SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd");
							Date data = new Date();
							int pozycja=0, kurier=0;
							ResultSet rs = stmt.executeQuery("SELECT z.pozycja, z.status, z.uwagi, z.id_paczki, p.data_nad, p.data_dor FROM zamowienia z, paczki p WHERE id_zamowienia='"+request.getParameter("no")+"';");
							if(!rs.first()) out.write("<br/><table cellspacing='10px'><tr><td><img src='images/paczka2.png' height=50px width=50px></td><td>Paczka nie została odnaleziona.<br/> Sprawdź numer przesyłki. </td></tr></table><br/>");
							else{
								rs.previous();
								while(rs.next()){
									status=rs.getString("z.status");
									pozycja=rs.getInt("z.pozycja");
									uwagi=rs.getString("z.uwagi");
									data_nad=rs.getString("p.data_nad");
									data_dor=rs.getString("p.data_dor");
									}
								rs = stmt.executeQuery("SELECT nazwa FROM oddzialy WHERE id='"+pozycja+"';");
								while(rs.next()){
									oddzial=rs.getString("nazwa");
								}
					
									if(sesja.getAttribute("lang").equals("en")) out.write("<h3>The current status of the shipment:</h3>");
									else out.write("<h3>Aktualny stan przesyłki:</h3>");
						%>			
									<div style="width: 80%">
											<div>
												<div style="background-color: #ffffff;padding: 2px;border: 1px solid black;height: 40px;">
									<%if(status.equals("przyjeto")){ %>
													<div style="width: 10%; background-color: #33ff33; height: 100%; margin-top: 0px; float:left"><img src='images/lorry.png' style='float:right; height: 100%;'>&nbsp;</div>
													<div style="width: 90%; background-color: #d2d2d2; height: 100%; margin-top: 0px; float:left">&nbsp;</div>
												
									<%}else if(status.equals("w trakcie dostarczania") && pozycja!=1){ %>	
													<div style="width: 30%; background-color: #33ff33; height: 100%; margin-top: 0px; float:left"><img src='images/lorry.png' style='float:right; height: 100%;'>&nbsp;</div>
													<div style="width: 70%; background-color: #d2d2d2; height: 100%; margin-top: 0px; float:left">&nbsp;</div>
												
									<%}else if(status.equals("w trakcie dostarczania") && pozycja==1){%>	
													<div style="width: 50%; background-color: #33ff33; height: 100%; margin-top: 0px; float:left"><img src='images/lorry.png' style='float:right; height: 100%;'>&nbsp;</div>
													<div style="width: 50%; background-color: #d2d2d2; height: 100%; margin-top: 0px; float:left">&nbsp;</div>
												
									<%}else if(status.equals("oczekiwanie na dostarczenie")){ %>
													<div style="width: 70%; background-color: #33ff33; height: 100%; margin-top: 0px; float:left"><img src='images/lorry.png' style='float:right; height: 100%;'>&nbsp;</div>
													<div style="width: 30%; background-color: #d2d2d2; height: 100%; margin-top: 0px; float:left">&nbsp;</div>
												
									<%}else if(status.equals("dowoz do klienta")){ %>
													<div style="width: 90%; background-color: #33ff33; height: 100%; margin-top: 0px; float:left"><img src='images/lorry.png' style='float:right; height: 100%;'>&nbsp;</div>
													<div style="width: 10%; background-color: #d2d2d2; height: 100%; margin-top: 0px; float:left">&nbsp;</div>
												
									<%}else if(status.equals("dostarczono")){ %>
													<div style="width: 100%; background-color: #33ff33; height: 100%; margin-top: 0px; float:left"><img src='images/lorry.png' style='float:right; height: 100%;'>&nbsp;</div>
													<div style="width: 0%; background-color: #d2d2d2; height: 100%; margin-top: 0px; float:left">&nbsp;</div>
									<%}else if(status.equals("do odbioru")){ %>
													<div style="width: 0%; background-color: #33ff33; height: 100%; margin-top: 0px; float:left">&nbsp;</div>
													<div style="width: 100%; background-color: #d2d2d2; height: 100%; margin-top: 0px; float:left">&nbsp;</div>
									<%}else if(status.equals("odbior przez kuriera")){ %>
													<div style="width: 10%; background-color: #33ff33; height: 100%; margin-top: 0px; float:left">&nbsp;</div>
													<div style="width: 90%; background-color: #d2d2d2; height: 100%; margin-top: 0px; float:left">&nbsp;</div>
									<%}else { %>
													<div style="width: 100%; background-color: #ff0033; height: 100%; margin-top: 0px; float:left">&nbsp;</div>
													<div style="width: 0%; background-color: #d2d2d2; height: 100%; margin-top: 0px; float:left">&nbsp;</div>
									<%} %>				
												</div>												
											</div>											
									</div>	
									<br/><br/>
									<%if(sesja.getAttribute("lang").equals("en")){%>
										<table class=opcje >
										<tr>
										<td align="center" valign="middle"> 
											<table cellspacing='20px'>
											<tr>
												<td rowspan="5"><img src='images/paczka2.png' height=70px width=70px></td>
												<td>Status:</td>
												<td width="200" style='overflow: hidden;'>
												<%
													if(status.equals("przyjeto")) out.write("accepted");
													else if(status.equals("w trackie dostarczania")) out.write("during the delivery");
													else if(status.equals("oczekiwanie na dostarczenie")) out.write("waiting to deliver");
													else if(status.equals("dowoz do klienta")) out.write("deliver to the customer");
													else if(status.equals("dostarczono")) out.write("delivered");
													else out.write(status);
												%></td>
											</tr>
											<tr>
												<td>date of dispatch:</td><td><%out.write(data_nad);%></td>
											</tr>
											<tr>
												<td>
												<%
												if(status.equals("dowoz do klienta")) out.write("Expected date of delivery:</td><td>"+sdf.format(data));
												else if(status.equals("dostarczono")) out.write("Date of delivery:</td><td>"+data_dor);											
												else out.write("Expected date of delivery:</td><td> - ");
												%>											
												</td>
											</tr>
											<tr>							
												<td>Last position:</td><td><%out.write(oddzial);%></td>
											</tr>
											<tr>
												<td>Comments:</td><td><% if(uwagi!=null) out.write(uwagi); else out.write("none");%></td>
											</tr>
											
											</table>
										</td>
										</tr>
										</table>
									<%}else{ %>
										<table class=opcje >
										<tr>
										<td align="center" valign="middle"> 
											<table cellspacing='20px'>
											<tr>
												<td rowspan="5"><img src='images/paczka2.png' height=70px width=70px></td>
												<td>Status:</td><td width="200" style='overflow: hidden;'><%out.write(status);%></td>
											</tr>
											<tr>
												<td>Data nadania:</td><td><%out.write(data_nad);%></td>
											</tr>
											<tr>
												<td>
												<%
												if(status.equals("dowoz do klienta")) out.write("Przewidywana data dostawy:</td><td>"+sdf.format(data));
												else if(status.equals("dostarczono")) out.write("Data doręczenia:</td><td>"+data_dor);											
												else out.write("Przewidywana data dostawy:</td><td> - ");
												%>											
												</td>
											</tr>
											<tr>							
												<td>Ostatnia pozycja:</td><td><%out.write(oddzial);%></td>
											</tr>
											<tr>
												<td>Uwagi:</td><td><% if(uwagi!=null) out.write(uwagi); else out.write("brak");%></td>
											</tr>
											
											</table>
										</td>
										</tr>
										</table>
									<% 	}														
							}
						} catch (SQLException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}%>
		</fieldset>
		</div>	
<%}else{ 
	if(sesja.getAttribute("lang").equals("en")){%>
		<div class=formularz style='width:50%;'>
		<fieldset class=obrys>
		<br/>
		Enter the shipment number:
		<br/><br/>
		<form method='post' name='package' onSubmit='SprawdzNumer2()'>
		<textarea style="width:80%; height:80px;" name='no' id='no' onKeyPress='TylkoNumer2(event)'></textarea><br>
		<br/>
		<input class=przycisk type='button' value='Track' style="width=100px;" onClick='SprawdzNumer2()' >
		<input class=przycisk type='button' value='Clean' style="width=100px;" onClick='this.form.reset()'>
		<br/>
		</form>
		</fieldset>
		</div>	
	<%}else{ %>
		<div class=formularz style='width:50%;'>
		<fieldset class=obrys>
		<br/>
		Wprowadź numer zamówienia:
		<br/><br/>
		<form method='post' name='package' onSubmit='SprawdzNumer2()'>
		<textarea style="width:80%; height:80px;" name='no' id='no' onKeyPress='TylkoNumer2(event)'></textarea><br>
		<br/>
		<input class=przycisk type='button' value='Śledź paczkę' style="width=100px;" onClick='SprawdzNumer2()'>
		<input class=przycisk type='button' value='Wyczy&#347;&#263;' style="width=100px;" onClick='this.form.reset()'>
		<br/>
		</form>
		</fieldset>
		</div>	
<%}}%>
</div>
</body>
</html>